<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title>网投彩票代理系统</title>
<link rel="stylesheet" type="text/css" href="__TEMPLATE__/webfile/css/login.css" />
</head>
<script src="__TEMPLATE__/webfile/js/jquery.js"></script>
<body>
<img src="__TEMPLATE__/webfile/img/login2.png" alt="">
<div class="title">网投彩票代理系统</div>
<div class="login">
    <div class="form-title">用户登录</div>
       <form id='form1' name='form1' method='post' action=''>
            <ul class="list">
                <li>
                    <label>用户名：</label>
                    <input type="text" name="username" id="username"/>
                    <div class="error"></div>
                </li>
                <li>
                    <label>密 &nbsp;&nbsp;码：</label>
                    <input type="password" name="password" id="password"/>
                    <div class="error"></div>
                </li>
            </ul>
           <div type="submit" class="submit submit2">登 &nbsp;&nbsp;&nbsp;&nbsp;录</div>
       </form>
</div>
</body>
<script>
    $(document).ready(function(){
        var name=false;
        var pass=false;
        var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
        var reg2= new RegExp("^[a-z]");
//用户名校验
        $("#username").blur(function() {
            var that=$('#username').siblings('.error').get(0);
            name=false;
             if($(this).val().trim()===''){
                 that.innerText='用户名不能为空！';
             }else if(reg.test($(this).val())){
                 that.innerText='用户名不能为汉字';
             }else if($(this).val().length<=5||$(this).val().length>=15){
                 that.innerText='用户名长度在5-15之间';
             }
             else{
                 name=true;
                 that.innerText=''
             }
        });
//密码校验
        $("#password").blur(function() {
            var that=$('#password').siblings('.error').get(0);
            pass=false;
            if($(this).val().trim()===''){
                that.innerText='密码不能为空！'
            }else if(!reg2.test($(this).val())){
                that.innerText='密码请以字母开头';
            }else if(reg.test($(this).val())){
                that.innerText='密码不能为汉字';
            }else if($(this).val().length<=5||$(this).val().length>=20){
                that.innerText='密码长度在5-20之间';
            }else{
                pass=true;
                that.innerText=''
            }
        });
//提交处理
        $('.submit').eq(0).click(function(){
            if(pass===true&&name===true){
                $.ajax({
                    url:"{:url('agent/login')}",
                    type:"POST",
                    data:$('#form1').serialize(),
                    success: function(data) {
                    	console.log(data);
                        if(data=="ok"){
                            $('#password').siblings('.error').get(0).innerText='提交成功！';
                            window.location.href="{:url('agent/index')}";
                        }else{
                            $('#password').siblings('.error').get(0).innerText='提交失败！';
                        }
                    }
                });

            }else{
                $('#password').siblings('.error').get(0).innerText='提交失败！';
            }
        })



    })
</script>
</html>